package com.duoduo.admin.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.duoduo.common.core.constant.SecurityConstants;
import com.duoduo.common.core.util.Page;
import com.duoduo.common.core.util.PageRequest;
import com.duoduo.common.core.util.R;
import com.duoduo.common.security.annotation.Inner;
import com.duoduo.admin.api.dto.SysOauthClientDetailsDTO;
import com.duoduo.admin.api.feign.RemoteClientDetailsFeginClient;
import com.duoduo.admin.service.SysOauthClientDetailsService;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;

@RestController
@RequestMapping("sysOauthClientDetails")
@Tag(name = "系统客户端表接口", description ="系统客户端表访问接口")
public class SysOauthClientDetailsController implements RemoteClientDetailsFeginClient{
	
	@Autowired
	private SysOauthClientDetailsService sysOauthClientDetailsService;
	
	/**
	 * 分页
	 * @param request
	 * @return
	 */
	@PostMapping("page")
	@Operation(summary = "分页")
	public R<Page<SysOauthClientDetailsDTO>> page(PageRequest<SysOauthClientDetailsDTO> request){
		Page<SysOauthClientDetailsDTO> page = sysOauthClientDetailsService.page(request.getPage(),request.getPageSize(),request.getParam());
		return R.ok(page);
	}
	/**
	 * 详情
	 * @param id
	 * @return
	 */
	@GetMapping("{id}/get")
	@Operation(summary = "详情")
	public R<SysOauthClientDetailsDTO> get(@Parameter(description = "主键id") @PathVariable("id")String id){
		return R.ok(sysOauthClientDetailsService.get(id));
	}
	/**
	 * 创建
	 * @param id
	 * @return
	 */
	@Operation(summary = "创建")
	@PostMapping("create")
	public R<SysOauthClientDetailsDTO> create(SysOauthClientDetailsDTO request){
		sysOauthClientDetailsService.create(request);
		return R.ok();
	}
	/**
	 * 修改
	 * @param id
	 * @return
	 */
	@Operation(summary = "修改")
	@PutMapping("update")
	public R<SysOauthClientDetailsDTO> update(SysOauthClientDetailsDTO request){
		sysOauthClientDetailsService.update(request,request.getClientId());
		return R.ok();
	}
	/**
	 * 删除
	 * @param id
	 * @return
	 */
	@Operation(summary = "删除")
	@DeleteMapping("{id}/delete")
	public R<SysOauthClientDetailsDTO> delete(@Parameter(description = "主键id") @PathVariable("id")String id){
		sysOauthClientDetailsService.delete(id);
		return R.ok();
	}
	
	@Override
	public R<List<SysOauthClientDetailsDTO>> listClientDetails() {
		
		return R.ok(sysOauthClientDetailsService.listClientDetails());
	}
	@Inner
	@Override
	public R<SysOauthClientDetailsDTO> getClientDetailsById(String clientId) {
		return R.ok(sysOauthClientDetailsService.get(clientId));
	};
}
